package com.ems.mapper;

import com.ems.entity.OrderEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ems.vo.OrderVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 工单 Mapper 接口
 * </p>
 *
 * @author WuZH
 * @since 2023-11-04
 */
@Mapper
public interface OrderMapper extends BaseMapper<OrderEntity> {

    @Select ( value = "<script>SELECT * FROM order_info oi " +
            "<trim prefix=\"WHERE\" prefixOverrides=\"and | or\">" +
            "<if test='orderVo.stationId!=null'> AND oi.stationId=#{orderVo.stationId} </if>" +
            "</trim>LIMIT #{orderVo.page}, #{orderVo.limit}</script>" )
    List<OrderVo> queryList ( @Param ( "orderVo" ) OrderVo orderVo );

    @Select ( value = "<script>SELECT COUNT(1) FROM order_info oi " +
            "<trim prefix=\"WHERE\" prefixOverrides=\"and | or\">" +
            "<if test='orderVo.stationId!=null'> AND oi.stationId=#{orderVo.stationId} </if>" +
            "</trim></script>" )
    Integer queryCount ( @Param ( "orderVo" ) OrderVo orderVo );

    @Select ( value = "<script>SELECT * FROM order_info oi LEFT JOIN station_info si ON oi.stationId=si.id\n" +
            "<trim prefix=\"WHERE\" prefixOverrides=\"and | or\">" +
            "<if test='orderVo.id!=null'> AND oi.id=#{orderVo.id} </if>" +
            "<if test='orderVo.stationId!=null'> AND oi.stationId=#{orderVo.stationId} </if>" +
            "</trim></script>" )
    OrderVo querySingle ( @Param ( "orderVo" ) OrderVo orderVo );

}
